<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>赛马问题 - 逻辑推理的优雅解法</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8f9fa;
            color: #333;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #6B73FF 0%, #000DFF 100%);
            color: white;
        }
        .heading-serif {
            font-family: 'Noto Serif SC', serif;
        }
        .solution-card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .solution-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
        }
        .code-block {
            background-color: #2d2d2d;
            color: #f8f8f2;
            border-radius: 8px;
        }
        .step-number {
            width: 32px;
            height: 32px;
            background-color: #4F46E5;
            color: white;
            border-radius: 50%;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            margin-right: 12px;
            font-weight: bold;
        }
        .concept-icon {
            color: #4F46E5;
            margin-right: 8px;
        }
        .highlight-box {
            border-left: 4px solid #4F46E5;
            background-color: rgba(79, 70, 229, 0.05);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-6xl px-4">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="heading-serif text-4xl md:text-5xl font-bold mb-6 leading-tight">赛马问题解析</h1>
                    <p class="text-xl mb-8 opacity-90">如何用最少比赛次数找出最快的3匹马？</p>
                    <div class="flex items-center">
                        <div class="bg-white bg-opacity-20 px-4 py-2 rounded-full inline-flex items-center">
                            <i class="fas fa-clock mr-2"></i>
                            <span>逻辑推理</span>
                        </div>
                        <div class="bg-white bg-opacity-20 px-4 py-2 rounded-full inline-flex items-center ml-3">
                            <i class="fas fa-brain mr-2"></i>
                            <span>算法思维</span>
                        </div>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <div class="relative">
                        <div class="w-64 h-64 bg-white bg-opacity-20 rounded-full flex items-center justify-center">
                            <i class="fas fa-horse-head text-8xl text-white"></i>
                        </div>
                        <div class="absolute -bottom-5 -right-5 bg-yellow-400 text-gray-900 px-4 py-2 rounded-full font-bold shadow-lg">
                            7次比赛
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Problem Statement -->
    <section class="py-16 px-4">
        <div class="container mx-auto max-w-4xl">
            <div class="mb-12">
                <h2 class="heading-serif text-3xl font-bold mb-6 text-center">问题描述</h2>
                <div class="bg-white rounded-xl p-8 shadow-md highlight-box">
                    <p class="text-lg mb-4"><i class="fas fa-question-circle concept-icon"></i>有25匹马和5个赛道，每次最多只能赛5匹马，且没有计时器。请问最少需要多少次比赛，才能选出速度最快的前3匹马？</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Solution Overview -->
    <section class="py-16 px-4 bg-gray-50">
        <div class="container mx-auto max-w-4xl">
            <h2 class="heading-serif text-3xl font-bold mb-12 text-center">解决方案概述</h2>
            
            <div class="grid md:grid-cols-3 gap-8">
                <div class="solution-card bg-white p-6 rounded-xl">
                    <div class="text-4xl text-blue-600 mb-4">
                        <i class="fas fa-layer-group"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">分组比赛</h3>
                    <p class="text-gray-600">将25匹马分成5组，每组比赛一次，共5场比赛。</p>
                </div>
                
                <div class="solution-card bg-white p-6 rounded-xl">
                    <div class="text-4xl text-purple-600 mb-4">
                        <i class="fas fa-trophy"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">冠军赛</h3>
                    <p class="text-gray-600">让每组第一名比赛一次，确定最快的马。</p>
                </div>
                
                <div class="solution-card bg-white p-6 rounded-xl">
                    <div class="text-4xl text-green-600 mb-4">
                        <i class="fas fa-medal"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">决赛</h3>
                    <p class="text-gray-600">通过分析前几名的归属，再进行1-2场比赛确定第二名和第三名。</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Detailed Steps -->
    <section class="py-16 px-4">
        <div class="container mx-auto max-w-4xl">
            <h2 class="heading-serif text-3xl font-bold mb-12 text-center">详细步骤解析</h2>
            
            <div class="mb-10">
                <div class="flex items-start mb-6">
                    <div class="step-number">1</div>
                    <div>
                        <h3 class="text-xl font-bold">初始分组比赛</h3>
                        <p class="text-gray-700 mt-2">将25匹马分成5组（A-E），每组5匹马，进行5场比赛。记录每组内部的排名：A1>A2>A3>A4>A5，B1>B2>B3>B4>B5，依此类推。</p>
                    </div>
                </div>
                
                <div class="flex items-start mb-6">
                    <div class="step-number">2</div>
                    <div>
                        <h3 class="text-xl font-bold">冠军赛</h3>
                        <p class="text-gray-700 mt-2">让各组第一名（A1,B1,C1,D1,E1）比赛一次，假设结果是A1>B1>C1>D1>E1。这样我们可以确定A1是所有马中最快的。</p>
                    </div>
                </div>
                
                <div class="flex items-start mb-6">
                    <div class="step-number">3</div>
                    <div>
                        <h3 class="text-xl font-bold">候选马匹分析</h3>
                        <p class="text-gray-700 mt-2">现在需要确定第二名和第三名。可能的候选马匹包括：</p>
                        <ul class="list-disc pl-6 mt-2 space-y-1">
                            <li><strong>第二名</strong>：可能是A2或B1</li>
                            <li><strong>第三名</strong>：可能是A3、B2或C1</li>
                        </ul>
                    </div>
                </div>
                
                <div class="flex items-start">
                    <div class="step-number">4</div>
                    <div>
                        <h3 class="text-xl font-bold">决赛</h3>
                        <p class="text-gray-700 mt-2">让A2、B1、B2、C1比赛一次（共7场比赛），根据比赛结果可以确定第二名和第三名。</p>
                    </div>
                </div>
            </div>
            
            <div class="bg-blue-50 rounded-xl p-6 mt-10">
                <div class="flex">
                    <i class="fas fa-lightbulb text-2xl text-blue-600 mr-4 mt-1"></i>
                    <div>
                        <h3 class="text-xl font-bold text-blue-800 mb-2">关键洞察</h3>
                        <p class="text-blue-900">通过排除法和逻辑推理，我们可以大大减少需要的比赛次数。许多马匹在冠军赛后就可以被排除在前三名之外，只需要关注少数关键候选马。</p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Visualization -->
    <section class="py-16 px-4 bg-gray-50">
        <div class="container mx-auto max-w-4xl">
            <h2 class="heading-serif text-3xl font-bold mb-12 text-center">比赛流程可视化</h2>
            
            <div class="bg-white rounded-xl p-6 shadow-md">
                <div class="mermaid">
                    graph TD
                    A[初始25匹马] --> B[分组比赛: 5组 x 5匹马]
                    B --> C[冠军赛: 各组第一名比赛]
                    C --> D[确定A1是最快的马]
                    D --> E[分析可能的前三名候选]
                    E --> F[决赛: A2,B1,B2,C1比赛]
                    F --> G[确定第二名和第三名]
                </div>
            </div>
        </div>
    </section>

    <!-- Code Example -->
    <section class="py-16 px-4">
        <div class="container mx-auto max-w-4xl">
            <h2 class="heading-serif text-3xl font-bold mb-6 text-center">伪代码示例</h2>
            
            <div class="code-block p-6 rounded-lg overflow-x-auto">
                <pre><code class="language-java">
/**
 * 赛马问题解决方案
 * 这是一个逻辑推理问题，代码主要用于展示解题思路
 */
public class HorseRacing {
    /**
     * 求解赛马问题
     * @return 最少需要的比赛次数
     */
    public int minRaces() {
        // 步骤1: 将25匹马分成5组进行比赛，每组5匹马
        // 这一步需要5次比赛
        int races = 5;
        
        // 步骤2: 让每组的第一名进行一次比赛，确定最快的马
        // 这一步需要1次比赛
        races += 1;
        
        // 步骤3: 根据第二步比赛结果，再进行必要的比赛确定第二名和第三名
        // 这一步需要1次比赛
        races += 1;
        
        // 总共需要7次比赛
        return races;
    }
    
    /**
     * 详细解释赛马问题的解决思路
     */
    public void explainSolution() {
        System.out.println("赛马问题解决方案:");
        System.out.println("1. 首先将25匹马分成5组(A,B,C,D,E)，每组5匹马，进行5场比赛");
        System.out.println("   - 得到每组内部的排名: A1>A2>A3>A4>A5, B1>B2>B3>B4>B5, ...");
        System.out.println("2. 让各组第一名(A1,B1,C1,D1,E1)比赛一次");
        System.out.println("   - 假设结果是: A1>B1>C1>D1>E1");
        System.out.println("3. 分析可知:");
        System.out.println("   - 第一名肯定是A1");
        System.out.println("   - 第二名可能是A2或B1");
        System.out.println("   - 第三名可能是A3,B1,B2或C1");
        System.out.println("4. 让A2,B1,B2,C1再比赛一次，确定第二名和第三名");
        System.out.println("总共需要5+1+1=7次比赛");
    }
}
                </code></pre>
            </div>
        </div>
    </section>

    <!-- Summary -->
    <section class="py-16 px-4 bg-gradient-to-r from-blue-500 to-purple-600 text-white">
        <div class="container mx-auto max-w-4xl text-center">
            <i class="fas fa-check-circle text-5xl mb-6"></i>
            <h2 class="heading-serif text-3xl font-bold mb-6">问题解决</h2>
            <p class="text-xl mb-8">通过7次比赛可以确定25匹马中最快的前3名。</p>
            <div class="inline-block bg-white text-blue-600 px-6 py-3 rounded-full font-bold shadow-lg">
                <i class="fas fa-horse mr-2"></i> 最少需要7次比赛
            </div>
        </div>
    </section>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>